<template>
  <el-form :inline="true" :model="searchState" class="demo-form-inline">
    <el-form-item label="关键字">
      <el-input v-model="searchState.searchText" placeholder="请输入关键字" clearable />
    </el-form-item>
    <el-form-item label="创建时间">
      <el-date-picker
        v-model="searchState.timeRange"
        type="daterange"
        range-separator="至"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        value-format="YYYY-MM-DD"
        size="small"
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSearch">搜索</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { reactive, computed } from "vue";
const emits = defineEmits(["search"]);
const searchState = reactive({
  searchText: "",
  timeRange: [],
});
const onSearch = () => {
  emits("search", searchParams.value);
};
const searchParams = computed(() => {
  return {
    searchText: searchState.searchText,
    start: searchState.timeRange[0] || "",
    end: searchState.timeRange[1] || "",
  };
});
</script>

<style scoped></style>
